import React from 'react'
export default class BindEvent extends React.Component {
    constructor() {
        super()
        this.state = {
            msg: "哈哈",
            name: 'zhangsan',
            age: 22,
            gender: '男'
        }
    }
    render() {
        return <div>
            BindEvent组件
            <button onClick={() => this.myClickHandler(this.state.msg)}>按钮</button>
            <h3>{this.state.msg}</h3>
            <input type='text' onChange={()=>this.txtChanged()} ref='txt' style={{ width: '100%' }} value={this.state.msg} />
        </div>
    }
    myClickHandler = (i) => {
        this.setState({
            msg: "111" + i
        }, () => {
            console.log(this.state.msg)
        })
    }
    txtChanged=()=>{
        const newVal = this.refs.txt.value
        this.setState({
            msg:newVal
        })
    }
}